<?php
class model_newagk_paper extends gdl_components_basemodel 
{

    public function primarykey() {
        return 'id';
    }

    public function tableName() {
        return 'agk_paper';
    }
	
	 
	 public function getInfo($id){

		if(empty($id)) return false;
		$result = $this->selectOne(['id'=>$id],'*');
		return $result;
		
	}
	public function getInfoArgLabelId($paperid=0)
    {
		if(!$paperid) return [];
		$paper_label = $this->getInfoArgOne(['id'=>$paperid], 'labelId');
		$labelId = [];
		if(!empty($paper_label['labelId'])){
			$labelId = explode(',',$paper_label['labelId']);
		}
		$chooseid = [];
		foreach($labelId as $v){
			$label =  explode('_',$v);
			$chooseid[$label[0]] = $label[1];
		}
		
		return $chooseid;
    }
	
	public function getInfoArgLabels($admin_reg=0)
    {
		if(!$admin_reg) return [];
		$paper_label = $this->getInfoArg(['admin_reg'=>$admin_reg], 'labelId');
		$labelId = [];
		$chooseid = [];
		if(!empty($paper_label)){
			foreach($paper_label as $vc){
				$labelId = explode(',',$vc['labelId']);
				foreach($labelId as $v){
					$label = explode('_',$v);
					$chooseid[$label[0]] = $label[1];
				}
			}
		}
		
		
		
		return $chooseid;
    }
	

	 
	public function getInfoArgOne($arrg=[],$field)
    {
		if(empty($arrg)) return false;
		return $this->selectOne($arrg, $field);
    }
	
	public function getInfoArg($arrg=[],$field)
    {
		if(empty($arrg)) return false;
		return $this->select($arrg, $field)->items;
    }
	 
	  public function fatherfo($id){

		if(empty($id)) $id=0;
		$inherit = $this->select(' father>0', 'father,version,name')->items; //admin_reg = '.$id.' and
		$bears = [];
		foreach($inherit as $v){
			$bears[$v['father']] = ['version'=>$v['version'],'name'=>$v['name']];
		}
				
		return $bears;
		
	 }
	 
	 //查询那些试卷不能删除的
	 public function doesExist($id){
		$basics = new model_newagk_basic();
		$datime = time()-3600; //这个是针对 那些延迟交卷的人
		$pid = $basics->select("pid in('" . $id . "') and unix_timestamp(endtime)<".$datime, 'pid')->items;
		$dwnid = [];
		foreach($pid as $v){
			$dwnid[] = $v['pid'];
		}
		
		return $dwnid;
	 }
	
}

